home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / BAckdrop.c next >
C/C++ Source or Header  |  1998-10-02  |  4KB  |  169 lines

  1. #include "MP.h"
  2. //#include "MPobject.h"
  3. #include <proto/datatypes.h>
  4. #include <proto/layers.h>
  5. #include <datatypes/datatypesclass.h>
  6. #include <datatypes/datatypes.h>
  7. #include <datatypes/pictureclass.h>
  8. #include "backfill.h"
  9. //#include "imagebackfill.h"
  10.  
  11. #define MPHOOK_OK   0
  12. #define MPHOOK_WARN 1
  13. #define MPHOOK_FAIL 2
  14.  
  15. //#define DEBUG_STACK
  16. //#define DEBUG
  17. #include <debug.h>
  18.  
  19. extern BOOL    V39;
  20.  
  21. void FreeBackfill(struct Backfill *B);
  22.  
  23. struct Backfill
  24. {
  25.   struct Node      bf_Node; // uses ln_Type;
  26.   struct Screen   *bf_Screen;
  27.   struct Hook     *bf_Hook;
  28. };
  29.  
  30. /*
  31. struct Backdrop
  32. {
  33.   struct Node bd_Node;
  34.   struct Screen *bd_Screen;
  35.   struct Window *bd_Window;
  36.   BOOL   bd_Loaded;
  37.   struct BackFillOptions  bd_BFOptions;
  38.   struct BackFillInfo     bd_BFInfo;
  39. };
  40. */
  41.  
  42. struct List BackdropList;
  43.  
  44. LONG AddBackdrop(struct Screen *Scr, struct DefaultNode *DN)
  45. {
  46.   struct Backfill *b;
  47.  
  48. DEBUG_CODE(DKP("AddBackdrop Scr=%8lx  DNode=%8lx\n",Scr,DN););
  49.  
  50.   if(Scr && DN && V39)
  51.   {
  52.     if(DN->BackdropType)
  53.     {
  54.       if(b=AllocVec(sizeof(*b),MEMF_CLEAR|MEMF_PUBLIC))
  55.       {
  56.         b->bf_Node.ln_Type=DN->BackdropType;
  57.         b->bf_Screen=Scr;
  58.             
  59. DEBUG_CODE(DKP("BackdropType=%ld\n",b->bf_Node.ln_Type););
  60.             
  61.         switch(DN->BackdropType)
  62.         {
  63.           case 1:
  64.             b->bf_Hook=Image_AllocBackfillHook(Scr,DN);
  65.             break;
  66.           case 2:
  67.             b->bf_Hook=RGB_AllocBackfillHook(Scr,DN);
  68.             break;
  69.         }     
  70.   
  71. DEBUG_CODE(DKP("bf_Hook=%ld\n",b->bf_Hook););
  72.         
  73.         if(b->bf_Hook)
  74.         {
  75.           struct Hook *oldhook;
  76.           struct Window *win;
  77.                   
  78.           Forbid();          
  79.           
  80.           oldhook=InstallLayerInfoHook(&Scr->LayerInfo,b->bf_Hook);
  81.           
  82.           if(0==oldhook) // if no previous hook
  83.           {
  84.             AddHead(&BackdropList,(struct Node *)b);
  85.             
  86. DEBUG_CODE(DKP("Hook Installed\n"););
  87.             
  88.             if(win=OpenWindowTags(0,WA_CustomScreen, Scr,
  89.                                     WA_Left        ,0,
  90.                                         WA_Top         ,0,
  91.                                         WA_Width       ,Scr->Width,
  92.                                         WA_Height      ,Scr->Height,
  93.                                         WA_Flags       ,WFLG_BACKDROP|WFLG_BORDERLESS|WFLG_SIMPLE_REFRESH|WFLG_NOCAREREFRESH,
  94.                                         WA_BackFill    ,0,
  95.                                     TAG_DONE))
  96.             {// refresh backdrop
  97.               CloseWindow(win);
  98.             }
  99.             
  100.             Permit();
  101.             return(MPHOOK_OK);
  102.           }
  103.           
  104. DEBUG_CODE(DKP("Hook Failed\n"););
  105.           
  106.           InstallLayerInfoHook(&Scr->LayerInfo,oldhook);
  107.           
  108.           Permit();
  109.         }
  110.         FreeBackfill(b);
  111.       }
  112.     }
  113.   }
  114.   return(MPHOOK_FAIL);
  115. }
  116.  
  117. void RemoveBackdrop(struct Screen *Scr)
  118. {
  119.   struct Backfill *b;
  120.   
  121. DEBUG_CODE(DKP("RemoveBackdrop Scr=%8lx\n",Scr););
  122.   
  123.   b=(struct Backfill *)BackdropList.lh_Head;
  124.   
  125.   while(b->bf_Node.ln_Succ)
  126.   {
  127.     if(b->bf_Screen==Scr)
  128.     {
  129.       struct Backfill *b2;
  130.       
  131. DEBUG_CODE(DKP("Removing Backdrop %8lx\n",b););
  132.       
  133.       InstallLayerInfoHook(&Scr->LayerInfo,0);
  134.       
  135.       b2=(struct Backfill *)b->bf_Node.ln_Succ;
  136.       
  137.       Remove((struct Node *)b);
  138.       FreeBackfill(b);
  139.       
  140.       b=b2;
  141.     }
  142.     else
  143.     {
  144.       b=(struct Backfill *)b->bf_Node.ln_Succ;
  145.     }
  146.   }
  147. }
  148.  
  149.  
  150. void FreeBackfill(struct Backfill *B)
  151. {
  152. DEBUG_CODE(DKP("FreeBackfill %8lx\n",B););
  153.  
  154.   if(B->bf_Hook)
  155.   {
  156.     switch(B->bf_Node.ln_Type)
  157.     {
  158.       case 1:// Image
  159.         Image_FreeBackfillHook(B->bf_Hook);
  160.         break;
  161.       case 2:// Color
  162.         RGB_FreeBackfillHook(B->bf_Hook);
  163.         break;
  164.     }
  165.   }
  166.   FreeVec(B);
  167. }
  168.  
  169.